package jfinal_framework;

import java.util.Arrays;

import com.framework.foundation.system.user.User;
import com.framework.foundation.util.Digests;
import com.framework.foundation.util.Encodes;

public class GenerateData {

	private static final int SALT_SIZE = 8;

	public static User randomNewUser() {
		String startDate = "2015-01-01 00:00:00";
		String endDate = "2015-12-31 23:59:59";

		User user = new User();
		user.set("username", RandomData.randomName("user"));
		user.set("realname", RandomData.randomName("User"));
		user.set("mobile", "158" + RandomData.randomNumber(8));
		user.set("email", RandomData.randomNumber(6) + "@qq.com");
		user.set("gender", RandomData.randomSome(Arrays.asList(new Boolean[] { true, false }), 1).get(0));
		user.set("lastVisit", RandomData.randomDate(startDate, endDate));
		user.set("previousVisit", RandomData.randomDate(startDate, endDate));

		byte[] salt = Digests.generateSalt(SALT_SIZE);
		user.set("salt", Encodes.encodeHex(salt));
		byte[] hashPassword = Digests.sha1("123456".getBytes(), user.getStr("salt").getBytes(), 1024);
		user.set("password", Encodes.encodeHex(hashPassword));

		return user;
	}
}
